<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>管理员修改工程师信息页面</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="./lib/layui/layui.js"
            charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="layui-fluid">

    <!---->
    <div class="layui-row">
        <form class="layui-form" method="post" enctype="multipart/form-data">
            <div class="layui-form-item">
                <div class="layui-input-inline">
                    <input type="hidden" id="id" name="id"
                           lay-verify="id" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="name" class="layui-form-label">
                    姓名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="name" name="name"
                           lay-verify="name" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="openid">微信openid</label>
                <div class="layui-input-inline">
                    <input type="text" id="openid" name="openid"
                           lay-verify="name" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="tel">手机号</label>
                <div class="layui-input-inline">
                    <input type="text" id="tel" name="tel"
                           lay-verify="rejectMsg" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="yzm" class="layui-form-label"> <span
                        class="x-red"></span>验证码
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="yzm" name="yzm"
                           lay-verify="unitid" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="goodat" class="layui-form-label"> <span
                        class="x-red"></span>擅长
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="goodat" name="goodat"
                           lay-verify="unitid" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"> <span
                        class="x-red"></span>个人头像
                </label>
                <div class="layui-input-inline">
                    <div class="layui-upload">
                        <button type="button" class="layui-btn layui-btn-normal" id="test1">选择文件</button>
                        <div class="layui-upload-list">
                            <img class="layui-upload-img" id="demo1" width="150px" height="150px">
                        </div>
                    </div>
                    <input type="hidden" id="person_pic" name="person_pic"
                           lay-verify="person_pic" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"> <span
                        class="x-red"></span>身份证正面
                </label>
                <div class="layui-input-inline">
                    <div class="layui-upload">
                        <button type="button" class="layui-btn layui-btn-normal" id="test3">选择文件</button>
                        <div class="layui-upload-list">
                            <img class="layui-upload-img" id="demo3" width="200px" height="150px">
                            <p id="demoText"></p>
                        </div>
                    </div>
                    <input type="hidden" id="id_zheng" name="id_zheng"
                           lay-verify="id_zheng" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"> <span
                        class="x-red"></span>身份证反面
                </label>
                <div class="layui-input-inline">
                    <div class="layui-upload">
                        <button type="button" class="layui-btn layui-btn-normal" id="test2">选择文件</button>
                        <div class="layui-upload-list">
                            <img class="layui-upload-img" id="demo2" width="200px" height="150px">
                        </div>
                    </div>
                    <input type="hidden" id="id_fan" name="id_fan"
                           lay-verify="id_fan" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <label class="layui-form-label"></label>
                <button class="layui-btn" lay-filter="update" lay-submit="" id="update">更新</button>
            </div>
        </form>
    </div>
</div>
    <script>layui.use(['form', 'layer', 'jquery', 'upload'], function () {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer,
            upload = layui.upload;
        //上传个人头像
        upload.render({
            elem: '#test1'
            , url: 'upload'       //上传路径
            /*, auto: false       //关闭自动上传
            , bindAction: '#test11'*/
            , accept: 'images'        //只允许上传图片
            , choose: function (obj) {                 //选择文件后的回调函数
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').prop('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                console.log(JSON.stringify(res));
                $("#person_pic").prop("value", res.msg);
                form.render();
            }
        });

        //上传身份证反面
        upload.render({
            elem: '#test2'
            , url: 'upload'       //上传路径
            /*, auto: false       //关闭自动上传
            , bindAction: '#test22'*/
            , accept: 'images'        //只允许上传图片
            , choose: function (obj) {                 //选择文件后的回调函数
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo2').prop('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                $("#id_fan").prop("value", res.msg);
                form.render();
            }
        });

        //上传身份证正面
        upload.render({
            elem: '#test3'
            , url: 'upload'       //上传路径
            /* , auto: false       //关闭自动上传
             , bindAction: '#test33'*/
            , accept: 'images'        //只允许上传图片
            , choose: function (obj) {                 //选择文件后的回调函数
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo3').prop('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                console.log(res)
                $("#id_zheng").prop("value", res.msg);
                form.render();
            }
        });

        var id = location.search.substring(1);
        $.get("findRepairMan", {id: id}, function (data) {
            $("#id").prop("value", data.data.id);
            $("#name").prop("value", data.data.name);
            $("#openid").prop("value", data.data.openid);
            $("#tel").prop("value", data.data.tel);
            $("#yzm").prop("value", data.data.yzm);
            $("#goodat").prop("value", data.data.goodat);
            $("#demo1").prop("src",  "/img/"+data.data.person_pic);
            $("#person_pic").prop("value", data.data.person_pic);
            $("#demo3").prop("src",  "/img/"+data.data.id_zheng);
            $("#id_zheng").prop("value", data.data.id_zheng);
            $("#demo2").prop("src", "/img/"+data.data.id_fan);
            $("#id_fan").prop("value", data.data.id_fan);
            form.render();//重绘表单
        });
        //监听提交
        form.on('submit(update)',
            function (d) {
                console.log(JSON.stringify(d.field));
                $.get("adminUpdateRepairMan", d.field, function (data) {
                    //alert(JSON.stringify(data));
                    if (data.code == 0) {
                        alert(data.msg);
                        xadmin.close();
                        xadmin.father_reload();
                    } else {
                        alert(data.msg);
                    }
                })
                return false;
            });
    });
    </script>
</div>

</body>

</html>
